package com.lgqz.himalayafm.fragment;


import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lgqz.himalayafm.R;
import com.lgqz.himalayafm.bean.ItemEntity;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 */
public class DiscoverNoveltyFragment extends Fragment {


    private ArrayList<ItemEntity> mDiscoveryColumns;

    public DiscoverNoveltyFragment() {
        // Required empty public constructor
    }

    public static DiscoverNoveltyFragment newInstance(ArrayList<ItemEntity> list) {
        Bundle args = new Bundle();
        args.putSerializable("list", list);
        DiscoverNoveltyFragment fragment = new DiscoverNoveltyFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        mDiscoveryColumns = bundle.getParcelableArrayList("list");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_discover_novelty, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.ll_novelty_discover);
        for (int i = 0; i < linearLayout.getChildCount(); i++) {
            LinearLayout childLayout = (LinearLayout) linearLayout.getChildAt(i);
            SimpleDraweeView draweeView = (SimpleDraweeView) childLayout.getChildAt(0);
            Uri uri = Uri.parse(mDiscoveryColumns.get(i).getCoverPath());
            draweeView.setImageURI(uri);
            setListener(draweeView,i);
            TextView textView = (TextView) childLayout.getChildAt(1);
            textView.setText(mDiscoveryColumns.get(i).getTitle());
        }
    }

    private void setListener(SimpleDraweeView draweeView, int i) {
        switch (i) {
            case 0:

                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
        }
    }
}
